package com.gao.jacksonconfig.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;
import java.math.BigDecimal;

/**
 * @author GaoXi
 * @date 2022/3/1 21:03
 */
@JsonComponent
public class CustomJsonSerial extends StdSerializer<BigDecimal> {
    protected CustomJsonSerial() {
        super(BigDecimal.class);
    }

    @Override
    public void serialize(BigDecimal bigDecimal, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString("￥"+bigDecimal.toString());
    }
}
